home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’97
/
Bugs in My Serial
/
Bugs in My Serial code
/
ScreenMatrix.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-27
|
3KB
|
135 lines
#include "ScreenMatrix.h"
#include "MacsBugSerialStuff.h"
void SMoveTo(short tY,short tX);
static void memset(Ptr inMem,char value,long inSize)
{
for(long z = 0;z<inSize;z++){
inMem[z] = value;
}
}
ScreenMatrix::ScreenMatrix()
{
memset((Ptr)fMatrix,' ',kWidth * kHeight);
fLastScrollWriteCol = kFirstScrollCol;
fLastCommandWriteCol = kFirstScrollCol;
fInvalidQ = false;
fScrollCount = 0;
}
void ScreenMatrix::RefreshScrollArea()
{
fInvalidQ = false;
fScrollCount = 0;
long numRows = ScrollAreaHeight();
for(long z = 1;z<=numRows;z++){
SMoveTo(z,1);
long theSize;
Ptr theLine = GetIndRow(z,theSize);
SerialDriver_SendBytes((unsigned char*)theLine,theSize);
}
}
void ScreenMatrix::Sync()
{
if(fInvalidQ){
fSyncCount++;
if(fSyncCount > 10000){
RefreshScrollArea();
}
}
}
Boolean ScreenMatrix::DrawChar(long inRow,long inCol,char inChar)
{
if((inCol <= kWidth) && (inRow <= kHeight)){
Boolean hadToScrollQ = false;
if(inRow == kBottomScrollRow){
if(inCol >= kFirstScrollCol){
if(inCol <= fLastScrollWriteCol){
// need to scroll
ScrollArea();
hadToScrollQ = true;
fLastScrollWriteCol = kFirstScrollCol;
}else{
fLastScrollWriteCol = inCol;
}
}
}else if(inRow == kCommandRow){
if(inCol >= kFirstScrollCol){
if(inCol <= fLastCommandWriteCol){
// clear the line and send it
memset(CalcStart(kFirstScrollCol,kCommandRow),' ',kWidth - (kFirstScrollCol-1));
long theSize;
Ptr theLine = GetIndRow(kCommandRow,theSize);
SMoveTo(kCommandRow,1);
SerialDriver_SendBytes((unsigned char*)theLine,theSize);
fLastCommandWriteCol = kFirstScrollCol;
}else{
fLastCommandWriteCol = inCol;
}
}
}
fMatrix[inRow-1][inCol-1] = inChar;
return hadToScrollQ;
}else{
return false;
}
}
Ptr ScreenMatrix::CalcStart(long inCol,long inRow)
{
return &fMatrix[inRow-1][inCol-1];
}
void ScreenMatrix::CopyRow(long fromRow,long toRow)
{
Ptr source = CalcStart(kFirstScrollCol,fromRow);
Ptr dest = CalcStart(kFirstScrollCol,toRow);
BlockMove(source,dest,kWidth - (kFirstScrollCol-1));
}
void ScreenMatrix::ScrollArea()
{
fInvalidQ = true;
fSyncCount = 0;
for(long row = 2;row <= kBottomScrollRow;row++){
CopyRow(row,row-1);
}
memset(CalcStart(kFirstScrollCol,kBottomScrollRow),' ',(kWidth - (kFirstScrollCol-1)));
fScrollCount++;
if(fScrollCount > 10){
RefreshScrollArea();
}
}
long ScreenMatrix::ScrollAreaHeight()
{
return kBottomScrollRow;
}
Ptr ScreenMatrix::GetIndRow(long inIndex,long &outSize)
{
outSize = kWidth;
return (Ptr) &fMatrix[inIndex-1][0];
}